package com.taowan.xunbaozl.morning_speak.design_pattern.day08;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by diql on 2016/3/2.
 */
public class FlyweightFactory {
    private static Map<Integer,Bird> birds = new HashMap<>();
    public static Bird getBird(int weight) {
        Bird bird = birds.get(weight);
        if(bird == null) {
            bird = new Duck(weight);
            birds.put(weight,bird);
        }
        return bird;
    }

    public static void allBird() {
        /*for(Map.Entry<Integer,Bird> entry : birds.entrySet()) {
                entry.getValue().getWeight();
        }*/
        System.out.println("一共" + birds.size() + "只");
    }
}
